//
//  TJHTTPClient.swift
//  weibo
//
//  Created by 简祖明 on 16/7/29.
//  Copyright © 2016年 汤娟. All rights reserved.
//

import UIKit
import AFNetworking

//枚举(请求方法)
enum HTTPClientType : String {
    case GET = "GET"
    case POST = "POST"
}

//封装网络工具类  AFHTTPSessionManager
class TJHTTPClient: AFHTTPSessionManager {
    //swift中的单例
    static let shareInstance : TJHTTPClient = {
        let afn = TJHTTPClient()
        
        //设置网络请求的content-type:text/plain
        afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
        return afn
    }()
    
    func request(Type:HTTPClientType,URLString: String, parameters: AnyObject?, progress: ((NSProgress) -> Void)?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?) {
        
        if Type == HTTPClientType.POST {
            self.POST(URLString, parameters: parameters, progress: progress, success: success, failure: failure)
        }
        else if Type == .GET {
            self.GET(URLString, parameters: parameters, progress: progress, success: success, failure: failure)
        }
    }
}

/*

TJHTTPClient.shareInstance .GET(<#T##URLString: String##String#>, parameters: <#T##AnyObject?#>, progress: <#T##((NSProgress) -> Void)?##((NSProgress) -> Void)?##(NSProgress) -> Void#>, success: <#T##((NSURLSessionDataTask, AnyObject?) -> Void)?##((NSURLSessionDataTask, AnyObject?) -> Void)?##(NSURLSessionDataTask, AnyObject?) -> Void#>, failure: <#T##((NSURLSessionDataTask?, NSError) -> Void)?##((NSURLSessionDataTask?, NSError) -> Void)?##(NSURLSessionDataTask?, NSError) -> Void#>)
*/